package n3087;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;

public class Main {

	static HashSet<String> set=new HashSet<String>();
	
	
	
	static char[] tmp=new char[201];
	
	static int bfs(String s1,String s2,String end)
	{
		set.clear();
		char[] narr=new char[s1.length()+s2.length()];
		for(int i=0;i<s1.length();i++)
		{
			narr[i*2+1]=s1.charAt(i);
			narr[i*2]=s2.charAt(i);
		}
		String str=String.valueOf(narr);
		int count=1;
		while(true)
		{
			if(set.contains(str)) {
				break;
			}
			if(str.equals(end))
			{
				return count;
			}
			set.add(str);
			narr=str.toCharArray();
			for(int i=0;i<s1.length();i++)
			{
				tmp[i*2+1]=narr[i];
				tmp[i*2]=narr[i+s1.length()];
			}
			str=String.valueOf(tmp,0,s1.length()*2);
			count++;
		}
		
		return -1;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{

		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		String line=bf.readLine();
		int total=Integer.parseInt(line);
		for(int i=0;i<total;i++)
		{
			int num=Integer.parseInt(bf.readLine());
			String s[]=new String[3];
			for(int j=0;j<3;j++)
			{
				s[j]=bf.readLine();
			}
			System.out.println((i+1)+" "+bfs(s[0],s[1],s[2]));
		}
	}

}
